<template>
  <div class="register-background">
    <el-card class="register-card">
      <h2 class="title">创建新账户</h2>
      <el-form>
        <el-form-item label="用户名" prop="username">
          <el-input v-model="registerForm.username"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input type="password" v-model="registerForm.password"></el-input>
        </el-form-item>
        <el-form-item label="昵称" prop="nickName">
          <el-input v-model="registerForm.nickName"></el-input>
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input v-model="registerForm.email"></el-input>
        </el-form-item>
        <el-form-item label="手机号" prop="phoneNumber">
          <el-input v-model="registerForm.phoneNumber"></el-input>
        </el-form-item>

        <el-form-item label="头像" prop="avatarUrl">
          <upload v-model="registerForm.avatarUrl" />
        </el-form-item>
        <el-form-item label="年龄" prop="age">
          <el-input v-model="registerForm.age"></el-input>
        </el-form-item>
        <el-form-item label="介绍信息" prop="introduction">
          <el-input v-model="registerForm.introduction"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" class="full-width" @click="handleRegister"
            >注册</el-button
          >
        </el-form-item>
        <el-form-item>
          <router-link to="/login" class="login-link"
            >已有账户？登录</router-link
          >
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script setup>
import { ref } from "vue";
import { useRouter } from "vue-router";
import { register } from "@/api/user";
import upload from "@/components/upload";
import { ElMessage } from "element-plus";
const router = useRouter();
const registerForm = ref({
  username: "",
  password: "",
});

const handleRegister = async () => {
  // 实际注册逻辑会在这里实现，例如 API 调用
  const res = await register({
    ...registerForm.value,
    status: 0,
  });
  if (res.status === "fail") {
    ElMessage.warning(res.message);
    return;
  }
  router.push("/login");
};
</script>

<style scoped>
.register-background {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background: linear-gradient(135deg, #4995d7 0%, #4995d7 100%);
}

.register-card {
  width: 100%;
  max-width: 360px;
  padding: 20px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.title {
  text-align: center;
  margin-bottom: 30px;
  color: #333;
}

.full-width {
  width: 100%;
}

.login-link {
  text-align: center;
  display: block;
  color: #333;
}
</style>